package flc.ast.adapter;


import static android.text.Spanned.SPAN_EXCLUSIVE_EXCLUSIVE;

import android.graphics.Color;
import android.text.SpannableStringBuilder;
import android.text.style.ForegroundColorSpan;
import android.widget.ImageView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.ConvertUtils;
import com.bumptech.glide.Glide;
import com.chad.library.adapter.base.provider.BaseItemProvider;
import com.chad.library.adapter.base.viewholder.BaseViewHolder;
import com.stark.picselect.entity.SelectMediaEntity;

import flc.ast.R;
import stark.common.basic.adaptermutil.StkProviderMultiAdapter;
import stark.common.basic.adaptermutil.StkSingleSpanProvider;
import stark.common.basic.utils.TimeUtil;

public class AddVideoAdapter extends StkProviderMultiAdapter<SelectMediaEntity> {

    public AddVideoAdapter() {
        addItemProvider(new StkSingleSpanProvider(126));
        addItemProvider(new AddVideoProvider());
    }

    private class AddVideoProvider extends BaseItemProvider<SelectMediaEntity> {
        @Override
        public int getItemViewType() {
            return StkProviderMultiAdapter.TYPE_VIEW;
        }

        @Override
        public int getLayoutId() {
            return R.layout.item_add_video;
        }

        @Override
        public void convert(@NonNull BaseViewHolder baseViewHolder, SelectMediaEntity selectMediaEntity) {
            Glide.with(getContext()).load(selectMediaEntity.getPath())
                    .into((ImageView) baseViewHolder.getView(R.id.ivAddVideoItemImg));
            baseViewHolder.setText(R.id.tvAddVideoItemName, selectMediaEntity.getMediaName());
            baseViewHolder.setText(R.id.tvAddVideoItemSize, ConvertUtils.byte2FitMemorySize(selectMediaEntity.getSize(), 0));
            baseViewHolder.setText(R.id.tvAddVideoItemDuration, TimeUtil.getMmss(selectMediaEntity.getDuration()));
            if (selectMediaEntity.isChecked()) {
                baseViewHolder.setBackgroundColor(R.id.llAddVideoItem, Color.parseColor("#1A2D53FF"));
            } else {
                baseViewHolder.setBackgroundColor(R.id.llAddVideoItem, 0);
            }
        }
    }


}
